package com.cdl.singletontest;

/**
 * @author cdl
 * @date 2025/10/4
 */
public class Singleton1 {


    //1,构造方法私有化
    private Singleton1(){ }

    // 2。声明一个本类对象
    private static Singleton1 instance = new Singleton1();
    //3。给外部提供静态方法获取实例
    public static Singleton1 getInstance(){
        return instance;
    }

    public void print(){
        System.out.println("测试饿汉式单例模式");
    }

}

class Demo{
    public static void main(String[] args){
        Singleton1 s1 = Singleton1.getInstance();
        Singleton1 s2 = Singleton1.getInstance();

        s1.print();
        s2.print();
        System.out.println(s1 == s2);
    }
}
